$(function () {
    var ordName = $("#ordName");
    var count = $("#count");
    var unit = $("#unit");
    var totalPrice = $("#totalPrice");
    var describe = $("#describe");
    var updateOrd = $("#updateOrd");
    var updateOrdForm = $("#updateOrdForm");


    ordName.attr("validateStatus", true);
    count.attr("validateStatus", true);
    unit.attr("validateStatus", true);
    totalPrice.attr("validateStatus", true);
    describe.attr("validateStatus", true);

    ordName.on({
        focus:function () {
            setStyles(ordName.next(), {'color':'red'}, "(请输入名称)", false);
        },
        blur:function () {
            var len = ordName.val().length;
            if (len > 0){
                setStyles(ordName.next(), {'color':'#87CEED'}, getImgTick() + "(Ok)", true);
            }else {
                setStyles(ordName.next(), {'color':'red'}, getImgCross() + "(不能为空)", false);
            }
        }
    });

    count.on({
        focus:function () {
            setStyles(count.next(), {'color':'red'}, "(请输入数量)", false);
        },
        blur:function () {
            var len = count.val().length;
            if (len > 0){
                setStyles(count.next(), {'color':'#87CEED'}, getImgTick() + "(Ok)", true);
            }else {
                setStyles(count.next(), {'color':'red'}, getImgCross() + "(不能为空)", false);
            }
        }
    });

    unit.on({
        focus:function () {
            setStyles(unit.next(), {'color':'red'}, "(请输入单位)", false);
        },
        blur:function () {
            var len = unit.val().length;
            if (len > 0){
                setStyles(unit.next(), {'color':'#87CEED'}, getImgTick() + "(Ok)", true);
            }else {
                setStyles(unit.next(), {'color':'red'}, getImgCross() + "(不能为空)", false);
            }
        }
    });

    totalPrice.on({
        focus:function () {
            setStyles(totalPrice.next(), {'color':'red'}, "(请输入金额)", false);
        },
        blur:function () {
            var len = totalPrice.val().length;
            if (len > 0){
                setStyles(totalPrice.next(), {'color':'#87CEED'}, getImgTick() + "(Ok)", true);
            }else {
                setStyles(totalPrice.next(), {'color':'red'}, getImgCross() + "(不能为空)", false);
            }
        }
    });

    describe.on({
        blur:function () {
            var len = describe.val().length;
            if (len > 0){
                setStyles(describe.next(), {'color':'#87CEED'}, getImgTick() + "(Ok)", true);
            }else {
                setStyles(describe.next(), {'color':'red'}, getImgCross() + "(不能为空)", false);
            }
        }
    });


    updateOrd.on({
        click:function (){
            console.log(ordName.attr("validateStatus"));
            console.log(count.attr("validateStatus"));
            console.log(unit.attr("validateStatus"));
            console.log(totalPrice.attr("validateStatus"));
            console.log(describe.attr("validateStatus"));
            if(ordName.attr("validateStatus") != "true"){
                ordName.blur();
            }else if(count.attr("validateStatus") != "true"){
                count.blur();
            }else if(unit.attr("validateStatus") != "true"){
                unit.blur();
            }else if(totalPrice.attr("validateStatus") != "true"){
                totalPrice.blur();
            }else if(describe.attr("validateStatus") != "true"){
                describe.blur();
            }else{
                if(confirm("是否确认提交数据")){
                    updateOrdForm.submit();
                }
            }
        }
    });

})